package com.example.demo1.controller;

import com.example.demo1.model.User;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-01-09
 * Time: 14:07
 */
@Controller
@RequestMapping("/Response")
public class ResponseController {
    @RequestMapping("/p1")
    public String p1() {
        return "/hello.html";
    }

    @ResponseBody
    @RequestMapping("/p2")
    public String p2() {
        return "<h1>返回静态代码</h1>";
    }

    @ResponseBody
    @RequestMapping("/p3")
    public User p3() {
        User user = new User();
        user.setName("zhangsan");
        user.setAge(17);
        user.setGender("male");
        return user;
    }

    @ResponseBody
    @RequestMapping("/p4")
    public User p4(HttpServletResponse response) {
        User user = new User();
        user.setName("zhangsan");
        user.setAge(17);
        user.setGender("male");
        response.setStatus(500);
        return user;
    }


    @ResponseBody
    @RequestMapping(value = "/p5",produces = "application/json")
    public String p5() {
        return "{\"success\":true}";
    }

    @ResponseBody
    @RequestMapping("/p6")
    public String p6(HttpServletResponse response) {
        response.setHeader("myKey","myValue");
        return "success";
    }

}
